package com.sunnada.edu.business.project.service;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import com.sunnada.edu.system.pub.common.AppContext;
import com.sunnada.edu.system.pub.common.MD5;
import com.sunnada.edu.system.pub.dao.PubDao;

public class ProjectMethods {

	public static int getProjectByName(HashMap<String, String> params) {
		PubDao dao = AppContext.getInstance().getPubDao();
		String name = params.get("name");
		String sql = "SELECT NAME FROM T_PROJECT T WHERE  NAME='" + name
				+ "' AND REC_STATUS!='2' ";
		return dao.selectListCot(sql);
	}

	public static int contractAdd(HashMap<String, String> params) {
		PubDao dao = AppContext.getInstance().getPubDao();
		String owner = params.get("owner");
		String fileName = params.get("fileName");
		String path = params.get("path");
		String loginUserId = params.get("loginUserId");
		String recId = UUID.randomUUID().toString();

		String sql = "insert into  T_CONTRACT(rec_id,name,type,type2,owner,path,rec_status,rec_time,rec_persion)  value('"
				+ recId
				+ "','"
				+ fileName
				+ "','2','2','"
				+ owner
				+ "','"
				+ path + "','0',now(),'" + loginUserId + "')";
		int num = dao.insert(sql);
		return num;

	}

	public static List getContractList(HashMap<String, String> params) {
		PubDao dao = AppContext.getInstance().getPubDao();
		String recId = params.get("recId");
		String sql = " select rec_id,name,path from t_contract where rec_status!='2' and owner='"
				+ recId + "'";
		return dao.selectList(sql);
	}

	public static int delContractById(HashMap<String, String> params) {
		PubDao dao = AppContext.getInstance().getPubDao();
		String recId = params.get("recId");
		String sql = " update t_contract set rec_status='2' where rec_id='"
				+ recId + "'";
		return dao.update(sql);
	}
	
	public static List getProjectList(HashMap<String, String> params) {
		PubDao dao = AppContext.getInstance().getPubDao();
		String name = params.get("name");
		String sql = "SELECT REC_ID,NAME FROM T_PROJECT T WHERE REC_STATUS!='2' ";
		return dao.selectList(sql);
	}
}
